package com.ruoyi.project.bas.msgTray.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.bas.msgTray.domain.TrayCodeMsg;
import com.ruoyi.project.bas.msgTray.service.ITrayCodeMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 托盘信息Controller
 * 
 * @author wz
 * @date 2023-03-27
 */
@Controller
@RequestMapping("/tray/msgTray")
public class TrayCodeMsgController extends BaseController
{
    private String prefix = "tray/msgTray";

    @Autowired
    private ITrayCodeMsgService trayCodeMsgService;

    @GetMapping()
    public String msgTray()
    {
        return prefix + "/msgTray";
    }

    /**
     * 查询托盘信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TrayCodeMsg trayCodeMsg)
    {
        startPage();
        List<TrayCodeMsg> list = trayCodeMsgService.selectTrayCodeMsgList(trayCodeMsg);
        return getDataTable(list);
    }

    /**
     * 导出托盘信息列表
     */
    @Log(title = "托盘信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrayCodeMsg trayCodeMsg)
    {
        List<TrayCodeMsg> list = trayCodeMsgService.selectTrayCodeMsgList(trayCodeMsg);
        ExcelUtil<TrayCodeMsg> util = new ExcelUtil<TrayCodeMsg>(TrayCodeMsg.class);
        return util.exportExcel(list, "msgTray");
    }

    /**
     * 新增托盘信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存托盘信息
     */
    @Log(title = "托盘信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TrayCodeMsg trayCodeMsg)
    {
        return toAjax(trayCodeMsgService.insertTrayCodeMsg(trayCodeMsg));
    }

    /**
     * 修改托盘信息
     */
    @GetMapping("/edit/{uuid}")
    public String edit(@PathVariable("uuid") Long uuid, ModelMap mmap)
    {
        TrayCodeMsg trayCodeMsg = trayCodeMsgService.selectTrayCodeMsgById(uuid);
        mmap.put("trayCodeMsg", trayCodeMsg);
        return prefix + "/edit";
    }

    /**
     * 修改保存托盘信息
     */
    @Log(title = "托盘信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TrayCodeMsg trayCodeMsg)
    {
        return toAjax(trayCodeMsgService.updateTrayCodeMsg(trayCodeMsg));
    }

    /**
     * 删除托盘信息
     */
    @Log(title = "托盘信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(trayCodeMsgService.deleteTrayCodeMsgByIds(ids));
    }
}
